# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=gopt
pkgver=8.1
pkgrel=0
pkgdesc="C library for parsing POSIX and GNU style command line arguments"
url="http://www.purposeful.co.uk/software/gopt/"
arch="all"
license="TFL"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/thoni56/$pkgname/archive/$pkgver.tar.gz"
builddir="$srcdir/$pkgname-$pkgver"

build() {
	cd "$builddir"

	$CC $CFLAGS -fPIC -pedantic -Wall -c gopt.c

	# Build shared lib.
	$CC $LDFLAGS -shared -o libgopt.so *.o

	# Build static lib.
	ar rc libgopt.a *.o
	ranlib libgopt.a

	# Build testing example.
	$CC $CFLAGS $LDFLAGS -L. gopt-usage.c -o gopt-usage -lgopt
}

check() {
	cd "$builddir"
	LD_LIBRARY_PATH=. ./gopt-usage --version
}

package() {
	local soname="libgopt.so.${pkgver%.*}"

	cd "$builddir"

	install -D -m 755 ${soname%.*} "$pkgdir"/usr/lib/$soname
	ln -s $soname "$pkgdir"/usr/lib/${soname%.*}

	install -D -m 644 libgopt.a "$pkgdir"/usr/lib/libgopt.a
	install -D -m 644 gopt.h "$pkgdir"/usr/include/gopt.h
}

sha512sums="2b5d6ab23a5aeccf22a9476f409f392e083ff481a6a0ae435e8e31197c3e3cf83085e1ce3a08162d98d1084420baff6cd45cef87eafec7827b82f58f2c8993c6  gopt-8.1.tar.gz"
